﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api.Beans;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    /// <summary>
    /// CompositeSerializer uses Composite class to handle the serialization of the
    /// composite key. The composite class uses the base serializers to make sure
    /// all components are serialized/deserialized correctly with the proper byte
    /// encoding.
    /// </summary>
    public class CompositeSerializer : AbstractSerializer<Me.Prettyprint.Hector.Api.Beans.Composite>
    {
        public static CompositeSerializer Instance = new CompositeSerializer();

        public CompositeSerializer()
        {
        }
        public override ComparatorType GetComparatorType()
        {
            return ComparatorType.COMPOSITETYPE;
        }
        public override ComparatorType ComparatorType
        {
            get
            {
                return ComparatorType.COMPOSITETYPE;
            }
        }
        public override byte[] ToBytes(Me.Prettyprint.Hector.Api.Beans.Composite obj)
        {
            return obj.Serialize().GetBuffer();
        }
        public override Utils.ByteBuffer ToByteBuffer(Me.Prettyprint.Hector.Api.Beans.Composite obj)
        {
            return new ByteBuffer(ToBytes(obj));
        }
        public override Me.Prettyprint.Hector.Api.Beans.Composite FromBytes(byte[] bytes)
        {
            return Composite.fromByteBuffer(new Utils.ByteBuffer(bytes));
        }
        public override Me.Prettyprint.Hector.Api.Beans.Composite FromByteBuffer(ByteBuffer buff)
        {
            return FromBytes(buff.GetBuffer());
        }
    }
}
